public class Solution377 {
    public int combinationSum4(int[] nums, int target) {
        int[] f=new int[target+1];
        f[0]=1;
        for (int j=1;j<=target;j++){
            for (int p=0;p<nums.length;p++) {
                if (j-nums[p]>=0) {
                    f[j]+=f[j-nums[p]];
                }
            }
        }
        return f[target];
    }

    public static void main(String[] args) {
        System.out.println(new Solution377().combinationSum4(new int[]{1,2,3},4));
    }
}
